<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Order Details</title>
</head>
<body>

<div id="Content">

    <div id="BackLink">
        <a th:href="@{/mainForm}">Return to Main Menu</a>
    </div>

    <div id="Catalog" th:text="${session.viewOrderMsg}">
        <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td align="center" valign="middle">
                    <table style="background-color: lightskyblue; margin: auto;">
                        <tr>
                            <th colspan="2">
                                Order #<span th:text="${session.order.orderId}"></span>
                                <span th:text="${session.order.orderDate}"></span>
                            </th>
                        </tr>
                        <tr>
                            <th colspan="2">Payment Details</th>
                        </tr>
                        <tr>
                            <td>Card Type:</td>
                            <td><span th:text="${session.order.cardType}"></span></td>
                        </tr>
                        <tr>
                            <td>Card Number:</td>
                            <td><span th:text="${session.order.creditCard}"></span></td>
                        </tr>
                        <tr>
                            <td>Expiry Date (MM/YYYY):</td>
                            <td><span th:text="${session.order.expiryDate}"></span></td>
                        </tr>
                        <!-- Billing Address -->
                        <tr>
                            <th colspan="2">Billing Address</th>
                        </tr>
                        <tr>
                            <td>First name:</td>
                            <td><span th:text="${session.order.billToFirstName}"></span></td>
                        </tr>
                        <!-- Add other billing address fields here -->
                        <!-- Shipping Address -->
                        <tr>
                            <th colspan="2">Shipping Address</th>
                        </tr>
                        <tr>
                            <td>First name:</td>
                            <td><span th:text="${session.order.shipToFirstName}"></span></td>
                        </tr>
                        <!-- Add other shipping address fields here -->
                        <!-- Order Items -->
                        <tr>
                            <td colspan="2">
                                <table>
                                    <tr>
                                        <th>Item ID</th>
                                        <th>Description</th>
                                        <th>Quantity</th>
                                        <th>Price</th>
                                        <th>Total Cost</th>
                                    </tr>
                                    <!-- Loop through line items -->
                                    <tr th:each="lineItem : ${session.order.lineItems}" th:if="${lineItem.quantity > 0}">
                                        <td>
                                            <a th:href="@{/itemForm(itemId=${lineItem.item.itemId})}" th:text="${lineItem.item.itemId}"></a>
                                        </td>
                                        <td>
                                            <!-- Check if item is not null -->
                                            <span th:if="${lineItem.item != null}">
                                                <!-- Display item attributes and name -->
                                                <span th:text="${lineItem.item.attribute1}"></span>
                                                <span th:text="${lineItem.item.attribute2}"></span>
                                                <span th:text="${lineItem.item.attribute3}"></span>
                                                <span th:text="${lineItem.item.attribute4}"></span>
                                                <span th:text="${lineItem.item.attribute5}"></span>
                                                <span th:text="${lineItem.item.product.name}"></span>
                                            </span>
                                            <!-- If item is null, display a message -->
                                            <span th:if="${lineItem.item == null}">
                                                <i>{description unavailable}</i>
                                            </span>
                                        </td>
                                        <td><span th:text="${lineItem.quantity}"></span></td>
                                        <td><span th:text="${#numbers.formatDecimal(lineItem.unitPrice, 2, 'COMMA', '$')}"></span></td>
                                        <td><span th:text="${#numbers.formatDecimal(lineItem.total, 2, 'COMMA', '$')}"></span></td>
                                    </tr>
                                    <tr>
                                        <th colspan="5">
                                            Total: <span th:text="${#numbers.formatDecimal(session.order.totalPrice, 2, 'COMMA', '$')}"></span>
                                        </th>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>

</div>

</body>
</html>
